# import threading
# import time
#
# def run(n):
#     print("task", n)
#     time.sleep(1)
#     print('2s')
#     time.sleep(1)
#     print('1s')
#     time.sleep(1)
#     print('0s')
#     time.sleep(1)
#
# if __name__ == '__main__':
#     t1 = threading.Thread(target=run, args=("t1",))
#     t2 = threading.Thread(target=run, args=("t2",))
#     t1.start()
#     t2.start()

# import threading
# import time
#
# class MyThread(threading.Thread):
#     def __init__(self, n):
#         super(MyThread, self).__init__()  # 重构run函数必须要写
#         self.n = n
#
#     def run(self):
#         print("task", self.n)
#         time.sleep(1)
#         print('2s')
#         time.sleep(1)
#         print('1s')
#         time.sleep(1)
#         print('0s')
#         time.sleep(1)
#
# if __name__ == "__main__":
#     t1 = MyThread("t1")
#     t2 = MyThread("t2")
#     t1.start()
#     t2.start()


import threading
import time

def run(n):
    print("task", n)
    # time.sleep(1)
    print('3')
    time.sleep(1)
    print('2')
    time.sleep(1)
    print('1')

if __name__ == '__main__':
    t = threading.Thread(target=run, args=("t1",), daemon=True)  # 推荐写法
    t.start()
    print("end")          # 主线程结束，守护线程立刻被回收


# import threading
# import time
#
# def run(n):
#     print("task", n)
#     time.sleep(1)       #此时子线程停1s
#     print('3')
#     time.sleep(1)
#     print('2')
#     time.sleep(1)
#     print('1')
#
# if __name__ == '__main__':
#     t = threading.Thread(target=run, args=("t1",))
#     t.setDaemon = True   #把子进程设置为守护线程，必须在start()之前设置
#     t.start()
#     t.join() # 设置主线程等待子线程结束
#     print("end")
